package com.gc.cscott.verify.contest2012jan;

import com.gc.cscott.verify.JavaTaskOutputVerifier;
import com.gc.cscott.verify.OutputVerifier.OutputStatus;
import com.gc.cscott.verify.OutputVerifier.VerifiedOutput;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 *
 * @author User
 */
public class CheckZ4Game implements JavaTaskOutputVerifier {

    public VerifiedOutput verify(String inputText, String outputText, String validationHintText) {
        final List<Integer> competitorOutput;
        try {
            competitorOutput= parseOutoutFormat(outputText);
        } catch(Exception e){
            return VerifiedOutput.outputIsWrong("Wrong output format");
        }
        final List<Integer> correctOutput = parseOutoutFormat(validationHintText);
        if (competitorOutput.equals(correctOutput)){
            return VerifiedOutput.outputIsCorrect();
        } else {
            return VerifiedOutput.outputIsWrong("Expected: "+correctOutput+", passed: "+competitorOutput);
        }
    }

    private List<Integer> parseOutoutFormat(String output){
        final List<Integer> result = new ArrayList<Integer>();
        for(String line:output.split("\\s+")){
            final String trim = line.trim();
            if (trim.isEmpty()==false){
                result.add(Integer.parseInt(trim));
            }
        }
        Collections.sort(result.subList(1, result.size()));
        return result;
    }


    public static void main(String[] args) {
        System.out.println(new CheckZ4Game().parseOutoutFormat("5\n 1\n2\n12 7 3"));
    }
}
